<?php
class UcAction extends Action {
    public function index(){
      if(!empty($_SESSION['loginname'])&&isset($_SESSION['loginname'])&&$_SESSION['loginstate']==1){//判断是否已经登录
	   $a="hello";
	   R('Uc/getorder');
	   $order=C('order');
	   $orderlist=$order[1];
	   $num=$order[0];
	   //print_r($orderlist);
	   
	   
	   $pageconfig=array(                     //参数
	      "tittle"=>"会员中心",
	   );
	   $this->assign("pageconfig",$pageconfig);
	   $this->assign("orderlist",$orderlist);
	   $this->assign("ordernum",$num);
       $this->display(); 
	  }else{
	    $headerurl=__APP__."/Index/login";
	    header('location:'.$headerurl);
	  }
    }
	public function getorder(){
	   $re=M('order');
	   $data['od_status']=0;
	   $order=$re->where($data)->select();
	   //echo json_encode($order);
	   $total=$re->count();
	   $nopay=$re->where('od_status=0')->count();
	   $rese=$re->where('od_status=1')->count();
	   $ziqu=$re->where('od_status=2')->count();
	   $pingjia=$re->where('od_status=3')->count();
	   $count=array("total"=>$total,"rese"=>$rese,'ziqu'=>$ziqu,'pingjia'=>$pingjia,'nopay'=>$nopay);
	   $array=array($count,$order);
	   C('order',$array);
	   if(isset($_POST)&&!empty($_POST)){
	     if($_POST['id']=="-1"){
	      $order=$re->select();
		  $order=json_encode($order);
		  $a=array('od_no','od_date','od_name','od_payway','od_sendway','od_status');
		  $b=array('订单编号','提交日期','收货人姓名','支付方式','配送方式','订单状态');
		  $order=str_replace($a,$b,$order);
		  echo $order;
		  }else{
	      $order=$re->where('od_status='.$_POST['id'])->select();
		  $order=json_encode($order);
		  $a=array('od_no','od_date','od_name','od_payway','od_sendway','od_status');
		  $b=array('订单编号','提交日期','收货人姓名','支付方式','配送方式','订单状态');
		  $order=str_replace($a,$b,$order);
		  echo $order;
		  }
		  
	   }
	   
	}
    public function myorder(){
      if(!empty($_SESSION['loginname'])&&isset($_SESSION['loginname'])&&$_SESSION['loginstate']==1){//判断是否已经登录	   
	   R('Uc/getorder');
	   $order=C('order');
	   $orderlist=$order[1];
	   $num=$order[0];
	   //print_r($orderlist);
	   
	   
	   $pageconfig=array(                     //参数
	      "tittle"=>"会员中心",
	   );
	   $this->assign("pageconfig",$pageconfig);
	   $this->assign("orderlist",$orderlist);
	   $this->assign("ordernum",$num);
       $this->display(); 
	  }else{
	    $headerurl=__APP__."/Index/login";
	    header('location:'.$headerurl);
	  }
	}
	
	public function order_detail(){
	  
      if(!empty($_SESSION['loginname'])&&isset($_SESSION['loginname'])&&$_SESSION['loginstate']==1){//判断是否已经登录
	    
	  	   
	   $get=$_GET['id'];
	   $order=M('order');
	   $list=$order->where('id='.$get)->select();
	   $od_user=$list[0]['od_user'];
	   if($_SESSION['loginname']==$od_user){
       $odarray=explode('@',$list[0]['od_content']);
	   unset($odarray[0]);
	   $goods=M('goods');
	   foreach($odarray as $index=>$value){
	     $od_detail[$index]=explode('$',$odarray[$index]);
		 $goods_list[$od_detail[$index][0]]=$goods->where('id='.$od_detail[$index][0])->select(); 	    
	   }
	   $pageconfig=array(                     //参数
	      "tittle"=>"订单详细",
	   );
	   $this->assign("pageconfig",$pageconfig);
	   $this->assign("odarray",$od_detail);
	   $this->assign("goodlist",$goods_list);
	   $this->assign("data",$list);
	   $this->display();
	   }else{
	   $this->error('此页无权浏览哦');
	   }
	  
	  }else{
	    $headerurl=__APP__."/Index/login";
	    header('location:'.$headerurl);
	  } 
	   
	}
	
	
	public function watch(){
	 
	}
	
	
}
?>